﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ExtBusiness.FlowOperation;
using ExtBusiness;
using System.Drawing;
using ExtBusiness.User;
using System.Configuration;

public partial class MyWindow_TaskInStepMapList : PageBase
{
    RequestFlowOperation flowOperation = new RequestFlowOperation();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindFlowName();
            BindData();
        }
    }

    /// <summary>
    /// 绑定该用户有权限的流程名称
    /// </summary>
    /// <!--addby zhongjian 20100608-->
    public void BindFlowName()
    {
        ClsWorkFlow newWorkflow = new ClsWorkFlow();
        DataTable dtTable = newWorkflow.GetWorkFlowByUserId(UserId, "");
        ddlFlow.Items.Clear();
        ddlFlow.Items.Add(new ListItem("所有流程", ""));
        foreach (DataRow row in dtTable.Rows)
        {
            ddlFlow.Items.Add(new ListItem(row["wname"].ToString(), row["wname"].ToString()));
        }
    }

    /// <summary>
    /// 绑定数据
    /// </summary>
    private void BindData()
    {
        string strWhere = string.Empty;
        DataTable dtSource = new DataTable();

        if (!string.IsNullOrEmpty(ddlFlow.Text))
        {
            strWhere += string.Format(" and 案件类型='{0}'",ddlFlow.Text);
        }
        if (!string.IsNullOrEmpty(txtName.Text))
        {
            strWhere += string.Format(" and c.申请单位 like '%{0}%'", txtName.Text);
        }
        if (!string.IsNullOrEmpty(txtIID.Text))
        {
            strWhere += string.Format(" and exists (select iid from ut_地图审核受理通知书 n where n.iid = c.顺序号 and n.input_index=0 and slbh like '%{0}%')", txtIID.Text);
        }

        if (!string.IsNullOrEmpty(Request["shtg"]))//已通过
        {
            strWhere += string.Format(" and c.顺序号 in (select iid from xt_instance_ext p where p.STATUS='{0}') ", Request["shtg"]);            
        }
        dtSource = flowOperation.AppearTaskInStep(UserId, strWhere,0);
        gvSerial.DataSource = dtSource;
        gvSerial.PageSize = SystemConfig.PageSize;
        gvSerial.RecordCount = dtSource.Rows.Count;
        gvSerial.DataBind();

        //窗口受理角色才具备拷贝功能
        Common.ConfigHelper conOper = new Common.ConfigHelper();
        if (GroupId != conOper.GetConfig("TxGroupId"))
        {
            gvSerial.Columns[4].Visible=false;
        }
    }

    protected void btnRefer_Click(object sender, EventArgs e)
    {
        BindData();
    }

    /// <summary>
    /// 绑定数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvSerial_OnLoadData(object sender, EventArgs e)
    {
        BindData();
    }

    /// <summary>
    /// 数据列创建事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvSerial_RowCreated(object sender, GridViewRowEventArgs e)
    {
        switch (e.Row.RowType)
        {
            case DataControlRowType.Header:
                break;
            case DataControlRowType.DataRow:
                {
                    DataRowView dtr = (DataRowView)e.Row.DataItem;
                    if (dtr != null)
                    {
                        Int64 nDbgq = Convert.ToInt64(dtr["督办过期"]);
                        Int64 nJdgq = Convert.ToInt64(dtr["结点过期"]);

                        if (nJdgq < 0)
                        {
                            e.Row.BackColor = Color.Red;
                        }
                        else if (nDbgq < 0)
                        {
                            e.Row.BackColor = Color.YellowGreen;
                        }

                        HyperLink hlProcess = e.Row.FindControl("hlProcess") as HyperLink;
                        if (null != hlProcess)
                        {
                            hlProcess.NavigateUrl = string.Format("javascript:HandleWorkItem('{0}','{1}','{2}')",
                                dtr["wiid"], dtr["顺序号"], dtr["所在岗位"]);
                        }

                        if (ClsWorkFlow.IsHaveSpecialWord(dtr["案件类型"].ToString()))
                        {
                            HyperLink hlCopyAndAdd = e.Row.FindControl("hlCopyAndAdd") as HyperLink;
                            if (null != hlCopyAndAdd)
                            {
                                hlCopyAndAdd.Text = "拷贝";
                                hlCopyAndAdd.NavigateUrl = string.Format("javascript:CopyAndAdd('{0}','{1}')", dtr["顺序号"], UserId);
                            }
                        }

                        HyperLink hlSpecailProcess = e.Row.FindControl("hlSpecailProcess") as HyperLink;
                        if (null != hlSpecailProcess)
                        {
                            hlSpecailProcess.NavigateUrl = string.Format("suspend_apply.aspx?ID={0}&s_gwid={1}&PageRedirect=../MyWindow/TaskInStepListBatch.aspx", dtr["顺序号"], dtr["wiid"]);
                        }

                        HyperLink hlBack = e.Row.FindControl("hlBack") as HyperLink;
                        if (dtr["isback"].ToString().Equals("1"))
                        {
                            if (null != hlBack)
                            {
                                hlBack.NavigateUrl = string.Format("javascript:openRemark('{0}')", dtr["wiid"]);
                                hlBack.Text = string.Format("{0}：退", dtr["前一用户"]); 
                            }
                        }
                        else
                        {
                            if (dtr["前一用户"] != DBNull.Value)
                            {
                                hlBack.Text = dtr["前一用户"].ToString();
                            }
                        }
                    }
                    break;
                }
        }
    }

    /// <summary>
    /// 优先级图标
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    protected string Getyou(string str)
    {
        if (str.EndsWith("0"))
            str = "top_ico_yxj1.gif";
        else if (str.Equals("1"))
            str = "top_ico_yxj2.gif";
        else
            str = "top_ico_yxj3.gif";

        return str;
    }  
}
